package com.woniuxy.dao;

import com.woniuxy.model.Account;
import com.woniuxy.model.Menus;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Kevin Martin
 * @since 2022-03-15
 */
public interface MenusDao extends BaseMapper<Menus> {

    @Select("SELECT  DISTINCT \n" +
            "wm.*\n" +
            "from woniu_menus wm\n" +
            "join woniu_rule_menus wrm\n" +
            "JOIN woniu_rule wr\n" +
            "join woniu_account_rule war\n" +
            "JOIN woniu_account wa\n" +
            "on wm.menus_id=wrm.menus_id and \n" +
            "wrm.rule_id = wr.rule_id AND\n" +
            "wr.rule_id=war.rule_id AND\n" +
            "war.account_id=wa.account_id\n" +
            "WHERE wa.account_id=#{id}")
    List<Menus> findMenusByUserId(Integer id);

    @Select("SELECT  \n" +
            "wm.menus_id\n" +
            "from woniu_menus wm\n" +
            "join woniu_rule_menus wrm\n" +
            "JOIN woniu_rule wr\n" +
            "on wm.menus_id=wrm.menus_id and \n" +
            "wrm.rule_id = wr.rule_id \n" +
            "WHERE wr.rule_id=#{ruleId}")
    List<Integer> seleMenusIdbyRuleId(Integer ruleId);
}
